class: center, middle, inverse, title-slide .title[ # Cheap Tricks ] .subtitle[ ## Prototyping Instruments ] .author[ ### Dr. Christopher Kenaley ] .institute[ ### Boston College ] .date[ ### 2021/9/28 ] --- class: inverse, top # In class today <!-- Add icon library --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css"> .pull-left[ Today we'll .... - Introduce what a Arduino is. - Using microcontrollers to do cool stuff. - How sensors work. - Metadata: data about data ] .pull-right[ ![](https://m.media-amazon.com/images/I/71z22cRPeeL.__AC_SY300_SX300_QL70_FMwebp_.jpg) ] --- class: inverse, top <!-- slide 1 --> ## What Arduino? .pull-left[ - power and interface - voltage and ground pins - digital vs. analog pins ] .pull-right[ ![](https://m.media-amazon.com/images/I/71z22cRPeeL.__AC_SY300_SX300_QL70_FMwebp_.jpg) ] --- class: inverse, top <!-- slide 1 --> ## Another IDE .pull-left[ - Just like R studio - write code for control - see output - load libraries ] .pull-right[ ![](https://www.techtonions.com/wp-content/uploads/2021/05/Getting-started-with-Arduino-IDE-Ficherd-Image.webp) ] --- class: inverse, top <!-- slide 1 --> ## Another IDE: first steps .pull-left[ - USB interface for data I/O - Also power - Set board type ] .pull-right[ ![](https://support.arduino.cc/hc/article_attachments/6366484431388/board-selector-labels.png) ] --- class: inverse, top <!-- slide 1 --> ## Arduino control .pull-left[ ```{} // Example testing sketch int currentTime void setup() { Serial.begin(9600); } void loop() { // Wait a few seconds between measurements. delay(2000); // Read temperature as Celsius (the default) float t = dht.readTemperature(); //add line to record current time currentTime=millis(); //add line to print current time Serial.print("Time = "); Serial.print(t); Serial.print(F("°C ")); } ``` ] .pull-right[ ![](https://www.techtonions.com/wp-content/uploads/2021/05/Getting-started-with-Arduino-IDE-Ficherd-Image.webp) - C-like code controls the microcontroller ] --- class: inverse, top <!-- slide 1 --> ## Arduino control .pull-left[ ```{} // Example testing sketch int currentTime void setup() { Serial.begin(9600); } void loop() { // Wait a few seconds between measurements. delay(2000); // Read temperature as Celsius (the default) float t = dht.readTemperature(); //add line to record current time currentTime=millis(); //add line to print current time Serial.print("Time = "); Serial.print(t); Serial.print(F("°C ")); } ``` ] .pull-right[ ![](https://docs.arduino.cc/static/5bfe133bdf2e1cdfe89194423d310cda/4ef49/serial-monitor-new-editor.png) - Output through serial monitor - Input, too! ] --- class: inverse, top <!-- slide 1 --> ## Sensors .pull-left[ - Many use small changes in voltage - so small, may need amplification ![](https://m.media-amazon.com/images/I/61R8InXl6RL._SX522_.jpg) DS18B20 sensor ] .pull-right[ ![](https://assets.omega.com/images/test-and-measurement-equipment/temperature/sensors/thermistors/ON-400_PROBES_l.jpg?imwidth=450) ] $140 --- class: inverse, top <!-- slide 1 --> ## Sensors .pull-left[ <img src="https://m.media-amazon.com/images/I/61R8InXl6RL._SX522_.jpg" width="50%"> `+` <img src="https://m.media-amazon.com/images/I/71z22cRPeeL.__AC_SY300_SX300_QL70_FMwebp_.jpg" width="50%"> `$25` ] .pull-right[ ![](https://www.elprocus.com/wp-content/uploads/2013/10/thermocouple.png) `$130` ] --- class: inverse, top <!-- slide 1 --> ## Metadata ```r f <- list.files("data") print(f) ``` ``` ## [1] "Haaland_Erling_3.csv" "Kane_Harry_1.csv" "Saka_Bukayo_5.csv" ## [4] "Salah_Mo_2.csv" "Son_Min_4.csv" ``` ```r m_1 <- strsplit(f[1],"_") %>% unlist print(m_1) ``` ``` ## [1] "Haaland" "Erling" "3.csv" ``` --- class: inverse, top <!-- slide 1 --> ## Metadata ```r print(m_1) ``` ``` ## [1] "Haaland" "Erling" "3.csv" ``` ```r d_1 <- read_csv(f[1]) %>% mutate( Last=m_1[1], First=m_1[2], trial=gsub(".csv","",m_1[3]) ) head(d_1) ``` ``` ## # A tibble: 6 × 5 ## Time Temp_C Last First trial ## <dbl> <dbl> <chr> <chr> <chr> ## 1 1 36.8 Haaland Erling 3 ## 2 2 39.7 Haaland Erling 3 ## 3 3 31.0 Haaland Erling 3 ## 4 4 30.9 Haaland Erling 3 ## 5 5 38.5 Haaland Erling 3 ## 6 6 39.8 Haaland Erling 3 ```